package com.sys.web.controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sys.dao.FileDao;
import com.sys.dao.impl.FileDaoImpl;


@WebServlet("/admin")
public class Admin extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getParameter("method");
		if(method.equals("arrange")) {
			try {
				arrange(request, response);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	private void arrange(HttpServletRequest request, HttpServletResponse response)
			throws SQLException {
		FileDao fDao = new FileDaoImpl();
		List<com.sys.domain.File> files = null;
		files = fDao.allFiles();
		request.setAttribute("fileArr", files);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}